package org.iblink.core.domain.model;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Class for representing an asset.
 * 
 * @author tpares
 *
 */
public class Asset {
  /**
   * Asset unique identifier
   */
  private long id;
  
  /**
   * The asset name
   */
  private String name;
  
  /**
   * The path to the file represented by this asset
   */
  private String path;
  
  /**
   * The categories in which this asset is referenced.
   */
  private Set<Category> categories;

  /**
   * @return the id
   */
  public long getId() {
    return id;
  }

  /**
   * @param id the id to set
   */
  public void setId(long id) {
    this.id = id;
  }

  /**
   * @return the name
   */
  public String getName() {
    return name;
  }

  /**
   * @param name the name to set
   */
  public void setName(String name) {
    this.name = name;
  }

  /**
   * @return the path
   */
  public String getPath() {
    return path;
  }

  /**
   * @param path the path to set
   */
  public void setPath(String path) {
    this.path = path;
  }

  /**
   * @return the categories
   */
  public Set<Category> getCategories() {
    return categories;
  }

  /**
   * @param categories the categories to set
   */
  public void setCategories(Set<Category> categories) {
    this.categories = categories;
  }
  
  public void addCategory(Category category) {
    if (categories == null) {
      categories = new HashSet<Category>();
    }
    
    categories.add(category);
  }
  
  public void removeCategory(Category category) {
    if (categories == null || categories.isEmpty()) {
      return;
    }
    for(Iterator<Category> iter = categories.iterator(); iter.hasNext();) {
      Category cat = iter.next();
      if (cat.getId() == category.getId()) {
        categories.remove(cat);
        return;
      }
    }
  }
  
  public String toString() {
    return getName();
  }
}
